package com.cr.admin.business.application.controller;

import com.cr.admin.business.application.pojo.entity.Application;
import com.cr.admin.business.application.pojo.param.ApplicationFollowParam;
import com.cr.admin.business.application.pojo.query.ApplicationQuery;
import com.cr.admin.business.application.service.ApplicationService;
import com.cr.common.response.JsonResult;
import com.cr.common.response.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController

@Api(tags = "申请单管理")
@RequestMapping("/api/bus/application")
public class ApplicationController {
    @Autowired
    private ApplicationService applicationService;

    @ApiOperation(value = "查询申请单列表")
    @GetMapping
    public JsonResult list(ApplicationQuery applicationQuery ) {
        PageData<Application> pageData = PageData.page(applicationQuery.getPageNum(), applicationQuery.getPageSize(), () -> applicationService.list(applicationQuery));
        return JsonResult.success(pageData);
    }


    @ApiOperation(value = "跟进申请单")
    @PutMapping()
    public JsonResult update(@Validated @RequestBody ApplicationFollowParam applicationFollowParam) {
        applicationService.followById(applicationFollowParam);
        return JsonResult.success();
    }


    @ApiOperation(value = "查询申请单详情")
    @GetMapping("{id}")
    public JsonResult getDetail(@PathVariable("id") Long id) {
        Application application = applicationService.selectById(id);
        return JsonResult.success(application);
    }


    @ApiOperation(value = "删除申请单")
    @DeleteMapping()
    public JsonResult delete(@RequestParam(name = "ids") List<Long> ids){
        applicationService.deleteByIds(ids);
        return JsonResult.success();
    }
}
